﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.Payment;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.BusinessLogic.Shipping;
using NopSolutions.NopCommerce.BusinessLogic.Alesko;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.BusinessLogic.Audit;

namespace NopSolutions.NopCommerce.Web
{
    public partial class OrderWizardPayPalPaymentStarting : BaseNopFrontendPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            if (Request.QueryString.Count == 0) return;

            string orderGuidStr = Request.QueryString["OrderGuid"];
            if (string.IsNullOrEmpty(orderGuidStr)) return;

            Guid orderGuid;
            if (!Guid.TryParse(orderGuidStr, out orderGuid)) return;

            Order order = OrderService.GetOrderByGuid(orderGuid);
            divContent.InnerHtml = this.MessageService.OrderPlacedCustomerNotificationMessage(order, order.CustomerLanguageId);
        }

        protected void btnNextStepPayment_Click(object sender, EventArgs e)
        {
            string orderGuidStr = Request.QueryString["OrderGuid"];
            if (string.IsNullOrEmpty(orderGuidStr)) return;

            Guid orderGuid;
            if (!Guid.TryParse(orderGuidStr, out orderGuid)) return;

            Order order = OrderService.GetOrderByGuid(orderGuid);
            this.PaymentService.PostProcessPayment(order);
        }

        protected void btnCancelOrder_Click(object sender, EventArgs e)
        {
            string orderGuidStr = Request.QueryString["OrderGuid"];
            if (string.IsNullOrEmpty(orderGuidStr)) return;

            Guid orderGuid;
            if (!Guid.TryParse(orderGuidStr, out orderGuid)) return;

            Order order = OrderService.GetOrderByGuid(orderGuid);
            order.OrderStatusId = (int)OrderStatusEnum.OrderCancelled;
            OrderService.UpdateOrder(order);
            Response.Redirect("~/default.aspx");
        }
    }
}